#include "StdAfx.h"
#include "ServiceFunctions.h"
#include "Defines_MazeSpecific.h"
#include "Cell.h"

CMazeCell :: CMazeCell()
{
	m_hasLeftWall = false;
	m_hasTopWall  = false;
	m_Banned      = false;

	m_MarkerType  = 0;

	m_row = m_col = -1;
}

void CMazeCell :: DrawMarker(float x_cell_size, float y_cell_size, bool hide_marker)
{
	m_LineType   = 0;
	m_MarkerType = 1;
	
	float x = x_cell_size / 2.0;
	float y = y_cell_size / 2.0;

	if(hide_marker)
	{
		m_MarkerType = 0;
		glColor3f(BACKGROUND_COLOR);
	}
	else
	{
		glColor3f(MARKER_COLOR);
	}
	glPointSize(MARKER_SIZE);

	myDrawDot((float)m_col*x_cell_size + x_cell_size / 2.0, 
		      (float)m_row*y_cell_size + y_cell_size / 2.0);

	glFlush();
}

void CMazeCell :: DrawRouteMarker(float x_cell_size, float y_cell_size, bool hide_marker)
{
	m_LineType   = 0;
	m_MarkerType = 2;
	
	float x = x_cell_size / 2.0;
	float y = y_cell_size / 2.0;

	if(hide_marker)
	{
		m_MarkerType = 0;
		glColor3f(BACKGROUND_COLOR);
	}
	else
	{
		glColor3f(ROUTE_MARKER_COLOR);
	}
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawDot((float)m_col*x_cell_size + x_cell_size / 2.0, 
		      (float)m_row*y_cell_size + y_cell_size / 2.0);

	glFlush();
}

void CMazeCell :: Draw(float x_cell_size, float y_cell_size)
{
	glPointSize(1.0f);

	if(m_hasTopWall)
	{
		glColor3f(LINE_COLOR);
	}
	else
	{
		glColor3f(BACKGROUND_COLOR);
	}

	myDrawLine((float)m_col*x_cell_size, 
		       (float)m_row*y_cell_size + y_cell_size, 
		       (float)m_col*x_cell_size + x_cell_size,
		       (float)m_row*y_cell_size + y_cell_size); 


	if(m_hasLeftWall)
	{
		glColor3f(LINE_COLOR);
	}
	else
	{
		glColor3f(BACKGROUND_COLOR);
	}

	myDrawLine((float)m_col*x_cell_size,
		       (float)m_row*y_cell_size, 
		       (float)m_col*x_cell_size,
			   (float)m_row*y_cell_size + y_cell_size);

	if(m_MarkerType == 1)
	{
		DrawMarker(x_cell_size, y_cell_size);
	}
	else if(m_MarkerType == 2)
	{
		DrawRouteMarker(x_cell_size, y_cell_size);
	}

	switch(m_LineType)
	{
		case 1: DrawHorLine (x_cell_size, y_cell_size); break;
		case 2: DrawVertLine(x_cell_size, y_cell_size); break;
		case 3: Draw9_12Line(x_cell_size, y_cell_size); break;
		case 4: Draw3_12Line(x_cell_size, y_cell_size); break;
		case 5: Draw3_6Line (x_cell_size, y_cell_size); break;
		case 6: Draw6_9Line (x_cell_size, y_cell_size); break;
	}

	glFlush();
}

void CMazeCell :: DrawHorLine (float x_cell_size, float y_cell_size)
{
	glColor3f(ROUTE_MARKER_COLOR);
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawLine((float)m_col*x_cell_size, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size,
		       (float)m_row*y_cell_size + y_cell_size/2.0); 

	glFlush();

	m_LineType = 1;
}

void CMazeCell :: DrawVertLine(float x_cell_size, float y_cell_size)
{
	glColor3f(ROUTE_MARKER_COLOR);
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size, 
		       (float)m_col*x_cell_size +  + x_cell_size/2.0,
			   (float)m_row*y_cell_size + y_cell_size);

	glFlush();

	m_LineType = 2;
}

void CMazeCell :: Draw9_12Line(float x_cell_size, float y_cell_size)
{
	glColor3f(ROUTE_MARKER_COLOR);
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawLine((float)m_col*x_cell_size, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size + y_cell_size/2.0); 

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size + y_cell_size); 

	glFlush();

	m_LineType = 3;
}

void CMazeCell :: Draw3_12Line(float x_cell_size, float y_cell_size)
{
	glColor3f(ROUTE_MARKER_COLOR);
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size + y_cell_size); 

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size,
		       (float)m_row*y_cell_size + y_cell_size/2.0); 
	
	glFlush();

	m_LineType = 4;
}

void CMazeCell :: Draw3_6Line (float x_cell_size, float y_cell_size)
{
	glColor3f(ROUTE_MARKER_COLOR);
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size,
		       (float)m_row*y_cell_size + y_cell_size/2.0); 

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size); 
	
	glFlush();

	m_LineType = 5;
}

void CMazeCell :: Draw6_9Line (float x_cell_size, float y_cell_size)
{
	glColor3f(ROUTE_MARKER_COLOR);
	glPointSize(ROUTE_MARKER_SIZE);

	myDrawLine((float)m_col*x_cell_size + x_cell_size/2.0, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size); 

	myDrawLine((float)m_col*x_cell_size, 
		       (float)m_row*y_cell_size + y_cell_size/2.0, 
		       (float)m_col*x_cell_size + x_cell_size/2.0,
		       (float)m_row*y_cell_size + y_cell_size/2.0); 

	glFlush();

	m_LineType = 6;
}

